/**
 * This command is used when one wishes to have several commands
 * run at the same time.  Unlike the regular asynchronous commands, all
 * will be treated as one group.  The complete event will only be fired when all elements
 * have fired their complete event
 * */
 
package com.as3.timbot.command
{
	import com.as3.timbot.command.AbstractCommand;
	import com.as3.timbot.command.CommandEvent;

	public class SyncGroup extends AbstractCommand
	{
		private var __syncArray:Array;
		private var __completeCount:Number;
		
		public function SyncGroup():void
		{
			__syncArray = new Array();
		}
		public function execute():void
		{
			super.begin();
			for(var i:Number<__syncArray.length;i++){
				__snycArray.execute();
			}
		}
		public function add(value:Command):void
		{
			value.addEventListener(CommandEvent.COMPLETE,completeHandler);
			__syncArray.push(value);
		}
		private function completeHandler(ev:CommandEvent):void
		{
			__completeCount ++;
			if(__completeCount = __syncArray.length){
				//the syncgroup is complete
				super.end();
			}else{
				var myValue:Number = (__completeCount/__syncArray.length)*100;
				super.progress(myValue);
			}
		}
	}
}